//
//  UsefulMacro.h
//  iCJTools
//
//  Created by YCJ on 2020/7/23.
//  Copyright © 2020 YCJ. All rights reserved.
//

#ifndef UsefulMacro_h
#define UsefulMacro_h


//------------------------全局相关-----------------------------

// weakSelf 宏定义
#undef WeakSelf
#define WeakSelf    @weakify(self)

#undef StrongSelf
#define StrongSelf  @strongify(self)

//通知管理
#define kNCAddObserver(obs,sel,nam,obj) [[NSNotificationCenter defaultCenter] addObserver:obs selector:@selector(sel) name:nam object:obj]
#define kNCRemoveObserver(obs,nam,obj) [[NSNotificationCenter defaultCenter] removeObserver:obs name:nam object:obj]



//------------------------适配相关-----------------------------

//真机/模拟器判断
#if TARGET_IPHONE_SIMULATOR//模拟器

#elif TARGET_OS_IPHONE//真机

#endif

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
//这里面 写 >8.0做的事
#elif __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0
//这里面写<8.0做的事
#endif

//判断系统版本是否大于某个版本
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

//判断系统大于ios7
#define IOS_7_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")

//判断系统大于ios8
#define IOS_8_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8")
//判断系统大于ios9
#define IOS_9_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9")

#define IOS_10_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10")



//------------------------视图布局-----------------------------

//判断是否是IPad
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

//判断是否是iPhone
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

/// 设备的Bounds
#define kScreenBounds [[UIScreen mainScreen] bounds]

/// 屏幕宽度/高度
#define kScreenWidth [UIScreen mainScreen].bounds.size.width

#define kScreenHeight [UIScreen mainScreen].bounds.size.height

/// App版本
#define APP_VERSION [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

//是否iPhoneX
#define kIPhoneX (kScreenHeight == 812 || kScreenHeight == 896 || kScreenHeight == 896)

//状态栏高度
#define kStatusBarHeight (!kIPhoneX ? 20.0 : 44.0)



//------------------------数据处理-----------------------------

/// 将NSData转成字符串
#define NSStringFromData(data) [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]

/// 将NSNumber专诚字符串
#define NSStringFromNumber(number) [@(number) description]

/// NSUserDefaults实例
#define User_Defaults [NSUserDefaults standardUserDefaults]

/// 格式化字符串
#define kStringFormat(fmt,...)  [NSString stringWithFormat:(fmt), ##__VA_ARGS__]


//------------------------打印日志-----------------------------

// __PRETTY_FUNCTION__ 可以用 NSStringFromSelector(_cmd))嘛？
#ifdef DEBUG // Debug 打印

/// 1.原始打印方法
//#define NSLog(fmt, ...) NSLog(fmt, ...)

/// 2.打印函数&行号&输入内容，比较简单
#define iCJLog(fmt, ...) NSLog((@"\n\n---------------- %s [Line %d] ----------------\n\n" fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)

/// 3.打印对象&文件&行号&函数&输入内容，比较详细
#define kFileName [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String]
#define kLogFmt(fmt,...) [[NSString stringWithFormat:(fmt), ##__VA_ARGS__] UTF8String]
#define iCJDLog(fmt,...) NSLog(@"\n\nclass: <%p %s:(%d) > method: %s \n\n%s\n", self, kFileName, __LINE__, __PRETTY_FUNCTION__, kLogFmt(fmt, ##__VA_ARGS__) )

/// 4.只打印函数&行号，作为标记使用
#define iCJTLog NSLog(@"%s [Line %d] ", __PRETTY_FUNCTION__, __LINE__);

/// 5.弹窗
#define iCJALog(fmt, ...)  { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__]  delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; }

#else // Release 不打印

#define NSLog(fmt, ...)
#define iCJLog(fmt, ...)
#define iCJDLog(fmt,...)
#define iCJTLog
#define iCJALog(fmt, ...)
#endif

#endif /* UsefulMacro_h */
